package com.qf.proxy.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Collection;

/**
 * 工具类操作String类型的公共方法类
 */
public class StringUtil {

	/**判断字符串是否为空或null*/
	public static boolean isEmpty(CharSequence cs) {
		return org.apache.commons.lang3.StringUtils.isEmpty(cs);
	}

	public static boolean isEmpty(Collection<?> collection) {
		return collection == null || collection.size() == 0;
	}

	//去除乱子符 除了字母数字汉字日语外的所有恶心字符
	// /u0800-/u4e00 (日文)
	// /u4e00-/u9fa5 (中文)
	public static String DelOther(String str) {
		return str.replaceAll("[^a-zA-Z0-9\\u0800-\\u4e00\\u4e00-\\u9fa5]", "").toLowerCase();
	}

	public static String encodeUrl(String str){
		String strEnc = "";
		try {
			strEnc = URLEncoder.encode(str, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return strEnc;
	}

	public static String decodeUrl(String str){
		String strDec = "";
		try {
			strDec = URLEncoder.encode(str, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return strDec;
	}
}
